package sajat.onlab;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;

public class MyLocationManager implements LocationListener { 
	public interface MyLocationListener { 
		public void onNewLocation(Location aNewLocation); 
		public void onStatus(String aMessage); 
		} 
	private final MyLocationListener myLocationListener; 
	private LocationManager locationManager; 
	public MyLocationManager(MyLocationListener aMyLocationListener) { 
		myLocationListener = aMyLocationListener;
	} 
	public void startLocationMonitoring(Context aContext,long timegps, long timenetwork, long meters) { 
		locationManager = (LocationManager) aContext.getSystemService(Context.LOCATION_SERVICE); 
		locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, timegps, meters,this); 
		locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, timenetwork, meters,this); 
		} 
	public void stopLocationMonitoring() { 
		if (locationManager != null) locationManager.removeUpdates(this); 
		} 
	public void onLocationChanged(Location location) { 
		myLocationListener.onNewLocation(location); 
		} 
	public void onProviderDisabled(String provider) { 
		myLocationListener.onStatus("Disabled: "+provider); 
		} 
	public void onProviderEnabled(String provider) { 
		myLocationListener.onStatus("Enabled: "+provider); 
		} 
	public void onStatusChanged(String provider, int status, Bundle extras) { 
		myLocationListener.onStatus("StatusChanged: "+provider+" status: "+status); 
		}
}
